package com.allenyuan.renderobject;

import java.io.File;

import com.allenyuan.render.ImageReader;
import com.allenyuan.render.JavaImageReader;
import com.allenyuan.render.Renderer;

public class RenderImage extends RenderObject {
	
	private RenderPoint pos;
	private int[] data;
	private int width;
	private int height;
	
	public RenderImage(RenderPoint pos) {
		super(RENDER_IMAGE);
		this.pos = pos;
	}
	
	public RenderImage() {
		super(RENDER_IMAGE);
	}

	@Override
	public void draw(Renderer r) {
		// TODO Auto-generated method stub
		r.drawImage(pos.getX(), pos.getY(), width, height, data);
	}

	public RenderPoint getPos() {
		return pos;
	}

	public int[] getData() {
		return data;
	}

	public void setData(int[] data) {
		this.data = data;
	}

	public int getWidth() {
		return width;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	public int getHeight() {
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}

	public void setPos(RenderPoint pos) {
		this.pos = pos;
	}

	@Override
	public void drawProgress(int mouse, RenderPoint point) {
		// TODO Auto-generated method stub
		switch (mouse) {
		case MOUSE_PRESS:
			this.pos = point;
			ImageReader reader = new JavaImageReader();
			File file = reader.getFile();
			RenderImage image = reader.read(file);
			this.width = image.getWidth();
			this.height = image.getHeight();
			this.data = image.getData();
			break;
		default:
			break;
		}
	}

	

}
